package com.ywb.controller;

import com.auth0.jwt.exceptions.TokenExpiredException;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.ywb.entity.vo.GalleryBean;
import com.ywb.service.GalleryBeanService;
import com.ywb.utils.JWTUtils;
import com.ywb.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.Cookie;
import java.util.List;

/**
 * 路由跳转控制器，控制index页面的路由跳转
 */
@Controller
public class RouterController extends BaseController {

    @Autowired
    GalleryBeanService galleryBeanService;
    /**
     * 主页面
     */
    @GetMapping({"/index", "/"})
    public String index(){
        if(!StringUtils.hasLength((String) request.getAttribute("userName"))) {
            request.setAttribute("userName", "Admin");
        }

        List<GalleryBean> galleries = galleryBeanService.list(null);
        request.setAttribute("galleries", galleries);
        if(!StringUtils.hasLength((String) request.getAttribute("pageName"))) {
            request.setAttribute("pageName", "main.jsp");
        }
        return "index";
    }
    @GetMapping("/keyword")
    public String keyword(Model model, String keyword){
        if(keyword.equals("教师列表")){
            model.addAttribute("pageNam", "/teacher/list.jsp");
        }
        if(keyword.equals("教师添加")){
            model.addAttribute("pageNam", "/teacher/list.jsp");
        }
        if(keyword.contains("教师")){
            model.addAttribute("pageNam", "/teacher/list.jsp");
        }
        if(keyword.contains("课程")){

        }

        return "index";
    }
}
